package com.clean.cleantotal.compores.compress

import android.graphics.Color
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.clean.cleantotal.R
import com.clean.cleantotal.base.BaseActivity
import com.clean.cleantotal.bean.FunType
import com.clean.cleantotal.databinding.ActivityCompressBinding
import com.clean.cleantotal.compores.compress.fragment.ImageFragment
import com.clean.cleantotal.utils.Utils

class CompressActivity : BaseActivity<ActivityCompressBinding>() {
    override val viewBinding: ActivityCompressBinding
        get() = ActivityCompressBinding.inflate(layoutInflater)

    override fun initView() {

        Utils.showScanDialog(this, FunType.COMPRESS_IMAGE, mBinding.loadingLayout.scanLayout, {
            animal = it
        }) {

        }
        animal?.duration = 3000
        mBinding.back.setOnClickListener { onBackPressed() }

        val list = ArrayList<Fragment>()
        val photoFragment = ImageFragment()
        photoFragment.arguments = Bundle().apply {
            putInt("type", 0)
        }
        val photoFragment1 = ImageFragment()
        photoFragment1.arguments = Bundle().apply {
            putInt("type", 1)
        }

        list.add(photoFragment)
        list.add(photoFragment1)
        mBinding.viewPage.adapter = object : FragmentStateAdapter(this) {
            override fun getItemCount(): Int {
                return list.size
            }

            override fun createFragment(position: Int): Fragment {
                return list[position]
            }
        }
        mBinding.viewPage.isUserInputEnabled = false
        mBinding.tvPhoto.setOnClickListener {
            mBinding.tvPhoto.setBackgroundResource(R.mipmap.icon_com_select)
            mBinding.tvComp.setBackgroundResource(R.drawable.transparent_bg)
            mBinding.tvPhoto.setTextColor(Color.parseColor("#FFFFFF"))
            mBinding.tvComp.setTextColor(Color.parseColor("#9BA0A1"))
            mBinding.viewPage.setCurrentItem(0, false)
        }
        mBinding.tvComp.setOnClickListener {
            mBinding.tvPhoto.setBackgroundResource(R.drawable.transparent_bg)
            mBinding.tvComp.setBackgroundResource(R.mipmap.icon_com_select)
            mBinding.tvComp.setTextColor(Color.parseColor("#FFFFFF"))
            mBinding.tvPhoto.setTextColor(Color.parseColor("#9BA0A1"))
            mBinding.viewPage.setCurrentItem(1, false)
        }

    }

}